// components/swiper-banner/index.js
import queryRect from "../../utils/query-rect"
import throttle from "../../utils/throttle"

const throttleQueryRect = throttle(queryRect, 1000, {
  trailing: true
})

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    swiperBanners: {
      type: Array,
      value: []
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    swiperHeight: 0,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    hanleSwiperImageLoaded: function () {
      // 获取图片的高度（如何去获取一个组件的高度）
      // const query = wx.createSelectorQuery()
      // 组件中需要用此方法
      const query = this.createSelectorQuery()
      throttleQueryRect(".swiper-image", query).then(res => {
        console.log("节流结果");
        const rect = res[0]
        this.setData({
          swiperHeight: rect.height
        })
      })
    },
  },
})